package cn.iocoder.yudao.module.vehicle.service.vehicleinfo;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.vehicle.controller.admin.vehicleinfo.vo.*;
import cn.iocoder.yudao.module.vehicle.dal.dataobject.vehicleinfo.vehicleinfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.vehicle.dal.mysql.vehicleinfo.vehicleinfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.vehicle.enums.ErrorCodeConstants.*;

/**
 * 车辆基本信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class vehicleinfoServiceImpl implements vehicleinfoService {

    @Resource
    private vehicleinfoMapper vehicleinfoMapper;

    @Override
    public Long createvehicleinfo(vehicleinfoSaveReqVO createReqVO) {
        // 插入
        vehicleinfoDO vehicleinfo = BeanUtils.toBean(createReqVO, vehicleinfoDO.class);
        vehicleinfoMapper.insert(vehicleinfo);

        // 返回
        return vehicleinfo.getId();
    }

    @Override
    public void updatevehicleinfo(vehicleinfoSaveReqVO updateReqVO) {
        // 校验存在
        validatevehicleinfoExists(updateReqVO.getId());
        // 更新
        vehicleinfoDO updateObj = BeanUtils.toBean(updateReqVO, vehicleinfoDO.class);
        vehicleinfoMapper.updateById(updateObj);
    }

    @Override
    public void deletevehicleinfo(Long id) {
        // 校验存在
        validatevehicleinfoExists(id);
        // 删除
        vehicleinfoMapper.deleteById(id);
    }

    @Override
        public void deletevehicleinfoListByIds(List<Long> ids) {
        // 删除
        vehicleinfoMapper.deleteByIds(ids);
        }


    private void validatevehicleinfoExists(Long id) {
        if (vehicleinfoMapper.selectById(id) == null) {
            throw exception(VEHICLEINFO_NOT_EXISTS);
        }
    }

    @Override
    public vehicleinfoDO getvehicleinfo(Long id) {
        return vehicleinfoMapper.selectById(id);
    }

    @Override
    public PageResult<vehicleinfoDO> getvehicleinfoPage(vehicleinfoPageReqVO pageReqVO) {
        return vehicleinfoMapper.selectPage(pageReqVO);
    }

}